#include <iostream>
using std::cout;
using std::endl;

//Point二维平面上面的点
class Point{
public:
    Point(int x, int y)
    :_ix(x)
    ,_iy(y)
    {
        //_ix = x;因为C++语法认为这些不能够算是初始化
        //而应该叫做赋值操作
        //_iy = y;
    }
    Point()
    :_ix(0)
    ,_iy(0)
    {
       // _ix = 0;
       // _iy = 0;
    }




private:
    int _ix;
    int _iy;
};


class A{
    int _num;
    double _price;
};
//sizeof(A) = 16

class B{
    int _num;
    int _price;
};

void test(){
    Point pt;//利用无参构造函数来创建一个pt对象
    cout << sizeof(Point) << endl;
    cout << sizeof(pt) << endl;
    cout << sizeof(A) << endl;
    cout << sizeof(B) << endl;
}



class x{
    char a;
    int b;
    short c;
    char d;
}AA;  //12

class y{
    int b;
    char a;
    char d;
    short c;
}BB;

void test2(){
    cout << "sizeof(x)=" << sizeof(AA) << endl;
    cout << "sizeof(y)=" << sizeof(BB) << endl;
}


class AA{
    int a;
    char b;
    short c;
    int d;
    class FF{
        int a1;
        char b1;
        short c1;
        char d1;
    }SFF;

    char e;

}SAA;

class BB{
    int a;
    char b;
    short c;
    int d;
    class FF{
        double a1;//因为出现了double 8字节类型的变量，所以最终对齐需要对齐到8字节
        char b1;
        short c1;
        char d1;
    }SFF;

    char e;
}SBB; //40

void test3(){
    cout << sizeof(SAA) << endl;
    cout << sizeof(SBB) << endl;
}



class CC{
    char e[2];
    short h;

    //class A需要对齐到8字节边界，起始必须也从8字节整数倍开始
    class A{
        int a;
        //最大成员整数倍开始存储
        //结构体本身也需要对齐，也就是最终需要存储double 8的整数倍
        double b;
        float c;
    }SAA;

}SCC;

void test4(){
    cout << sizeof(SCC) << endl;
}


void test5(){
    Point pt(1, 2);
    //指针本质：
    //里面存储的地址值 + 外加这个指针能够操作的大小空间
    //p里面存储了一个地址 + p可以操作8字节空间
    Point * p = &pt;
    int * pInt = (int *)p;
    cout << *pInt << endl;
    cout << *(pInt + 1) << endl;
}

int main()
{
    test5();
    return 0;
}

